package com.chinaoly.myapplication;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

import com.chad.library.adapter.base.BaseViewHolder;
import com.chen.helper.LightRecycleViewHelper;
import com.chen.helper.widget.RefreshRecycleView;

import java.util.ArrayList;
import java.util.List;

/**
 * recyclerview 演示 的demo
 */
public class RefreshRecvActivity extends AppCompatActivity {

    LightRecycleViewHelper<String> recycleViewHelper;
    private RefreshRecycleView rv;
    private Button btn;
    boolean enable = true;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_refresh_recv);
        rv = findViewById(R.id.rrv);
        btn = findViewById(R.id.btn_switch);


        //带刷新,不带上拉加载功能的
        recycleViewHelper = new LightRecycleViewHelper<String>(R.layout.item_refresh, rv, false) {
            @Override
            protected void setItemData(BaseViewHolder helper, String item) {
                helper.setText(R.id.tv_input, item);
            }

        };
        recycleViewHelper.postData(new Runnable() {
            @Override
            public void run() {
              loadData();
            }
        });
        btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                enable = !enable;
                recycleViewHelper.disableRefreshView(enable);
            }
        });
        recycleViewHelper.setRefresh(true);
        loadData();
    }



    private void loadData() {

        rv.postDelayed(new Runnable() {
            @Override
            public void run() {
                List<String> s = new ArrayList<>();
                s.add("sda1");
                s.add("sda2");
                s.add("sda3");
                s.add("sda4");
               recycleViewHelper.setListData(s);
            }
        }, 800);
    }
}
